package com.ssm.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.ssm.common.Message;
import com.ssm.dao.system.PrivilegeDao;
import com.ssm.entity.system.Privilege;
import com.ssm.service.system.PrivilegeService;
import com.ssm.web.Page;

@Service
public class PrivilegeServiceImpl implements PrivilegeService{
	
	@Autowired
	private PrivilegeDao privilegeDao;
	
	@Override
	public List<Privilege> initMenu(String roleId) {
		return privilegeDao.initMenu(roleId);
	}

	@Override
	public Page<Privilege> queryList(Privilege privilege) {
		Page<Privilege> page = new Page<>();
		try {
			page.setCount(privilegeDao.queryCount(privilege));
			page.setRecord(privilegeDao.queryList(privilege));
			page.setCurrentPage(privilege.getCurrentPage());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}

	@Override
	public Privilege getDetail(String privilegeId) {
		return privilegeDao.getDetail(privilegeId);
	}

	@Override
	public Message save(Privilege privilege) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Message delete(String[] ids) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Message update(Privilege privilege) {
		Message message = new Message();
		try {
			privilegeDao.update(privilege);
		} catch (DataAccessException e) {
			e.printStackTrace();
			message.setSuccess(false);
			message.setMessage("修改失败");
		}
		return message;
	}
}
